(ns x10.war
  [:use [x10.web :only (handler)]
        [x10.config :only (load-devices close-ports)]
        [ring.middleware.stacktrace :only (wrap-stacktrace)]
        [ring.middleware.file :only (wrap-file)]
        [ring.util.servlet :only (defservice)]]
  (:gen-class :extends javax.servlet.http.HttpServlet
	      :exposes-methods {init initSuper}))
  
(defn -init
  ([this config]
     (. this initSuper config)
     (let [db (.getInitParameter this "device-db")]
       (load-devices db)
       (.log this (str "Setting up *devices* from " db))))
  ([this]))	; because the super config will eventually try and call this.

(defn -destroy []
  (close-ports)
  (shutdown-agents))

(def app (wrap-stacktrace #'handler))
(defservice app)
